package cn.net.yugu.doraemon.netty.protocol.msg07;

import cn.net.yugu.doraemon.netty.protocol.MsgCode;
import io.netty.buffer.ByteBuf;
import org.apache.commons.codec.binary.Hex;

/**
 * 开门通知（同01号协议 加  开箱门状态）
 */
public class Msg071000011 extends Msg071 {
    public int time;

    public static final byte[] EMPTY_IMEI_CODE = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    public String checkSum;
    public Boolean checkCRC;
    public String code;
    public int userId;

    @Override
    public int getMsgCode() {
        return MsgCode.MSG_071000011.getCode();
    }

    @Override
    public void readTime(ByteBuf buffer) {
        time = buffer.readInt();
    }

    @Override
    public void readData(ByteBuf buffer) {
        byte[] bytes = new byte[2];
        buffer.readBytes(bytes);
        checkSum = new String(Hex.encodeHex(bytes)).toUpperCase();
        if(checkCRC(checkSum,  buffer)){
            checkCRC = true;
        }else{
            checkCRC = false;
        }
        bytes = new byte[12];
        buffer.readBytes(bytes);
        code = new String(Hex.encodeHex(bytes)).toUpperCase();
        userId = buffer.readInt();
    }
}
